package ESP.Control.A;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;

import com.alibaba.fastjson.JSONArray;

import ESP.Dao.BaseDao;
import ESP.Util.Encryption;
import ESP.VO.Role;

@Controller
public class a02 {
	@Resource
	public BaseDao baseDao;
	private Map<String, String> message = new HashMap<String, String>();
	private JSONArray rows;
	
	private String user_role_id;
	private String user_id;
	/**
	 * 查询用户
	 */
	public String queryUser(){
		if (this.user_role_id == null || this.user_role_id.equals("")) {
			baseDao.setReturnInfo(message, "N", "本次登录会话失效,请重新登录!");
			return "a02_msg";
		}
		if (!this.user_role_id.equals(Role.ADMIN)) {
			baseDao.setReturnInfo(message, "N", "您无此权限!");
			return "a02_msg";
		}
		List list = baseDao.queryUser(user_id);
		if (list.size() == 0 || list.isEmpty()) {
			baseDao.setReturnInfo(message, "N", "无匹配数据！");
			return "a02_rows";
		}else {
			this.rows = baseDao.toJson(list);
			baseDao.setReturnInfo(message, "Y", "查询"+list.size()+"条数据完毕");
			return "a02_rows";
		}
	}
	/**
	 * 密码初始化
	 */
	public String initPsw(){
		if (this.user_role_id == null || this.user_role_id.equals("")) {
			baseDao.setReturnInfo(message, "N", "本次登录会话失效,请重新登录!");
			return "a02_msg";
		}
		if (!this.user_role_id.equals(Role.ADMIN)) {
			baseDao.setReturnInfo(message, "N", "您无此权限!");
			return "a02_msg";
		}
		int i = baseDao.updateSqlForInt("update esp_user set user_password='"+Encryption.encryptionSHA1(user_id)
				+"' where user_id='"+user_id+"'");
		if (i == 1) {
			baseDao.setReturnInfo(message, "Y", "密码初始化完成！");
		}else {
			baseDao.setReturnInfo(message, "N", "密码修改失败！");
		}
		return "a02_msg";
	}
	/**
	 * get set
	 */
	public BaseDao getBaseDao() {
		return baseDao;
	}
	public void setBaseDao(BaseDao baseDao) {
		this.baseDao = baseDao;
	}
	public Map<String, String> getMessage() {
		return message;
	}
	public void setMessage(Map<String, String> message) {
		this.message = message;
	}
	public String getUser_id() {
		return user_id;
	}
	public void setUser_id(String userId) {
		user_id = userId;
	}
	public JSONArray getRows() {
		return rows;
	}
	public void setRows(JSONArray rows) {
		this.rows = rows;
	}
	public String getUser_role_id() {
		return user_role_id;
	}
	public void setUser_role_id(String userRoleId) {
		user_role_id = userRoleId;
	}
}
